package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;

/**
 * @author 李明洋
 * @date 2025/3/25 16:58
 * @version: 1.0
 */
public class JDBCDemo8 {
    public static void main(String[] args) {
        System.out.println("欢迎登录");
        Scanner sc = new Scanner(System.in);
        System.out.println("用户名");
        String username = sc.nextLine();
        System.out.println("密码");
        String password = sc.nextLine();
        System.out.println("昵称");
        String nickname = sc.nextLine();
        System.out.println("年龄");
        int age = sc.nextInt();

        try (Connection connection = DBUti1.getconnection();){
            String sql = "insert into user(username,password,nickname,age values(?,?,?,?)";
            PreparedStatement ps = connection.prepareStatement(sql);
            ps.setString(1,username);
            ps.setString(2,password);
            ps.setString(3,nickname);
            ps.setInt(4,age);

            int num = ps.executeUpdate();
            System.out.println(num>0?"注册成功":"注册失败");


        } catch (SQLException e) {
            throw new RuntimeException(e);
        }

    }
}
